<?php

class Painel_Form_Acessopaginas extends Zend_Form
{

    public function init()
    {
        $front = Zend_Controller_Front::getInstance();
        $controller = $front->getRequest()->getControllerName();
        $module = $front->getRequest()->getModuleName();
        $url = $front->getBaseUrl().'/'.$module.'/'.$controller;
        
        $id = $front->getRequest()->getParam('id', 0);
        
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        
        $this->setName('form_edt');
        
        $disabled = '';
        if($id > 0){
           $query = 'SELECT SQL_CACHE * FROM ACESSO_PAGINAS WHERE ACE_ID = ' . $id;
           $data = $db->fetchRow($query);
           $disabled = 'disabled="disabled"';
        }
        
        $el = new Zend_Form_Element_Hidden('ACE_ID',array('disableLoadDefaultDecorators' =>true));
        $el->addDecorators(array(array('ViewHelper'),array('Errors')))
            ->addFilter('Int');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('ACE_DAT');
        $el->setLabel('Data')->setRequired(true)
        ->addFilters(array('StripTags','StringTrim'))
        ->addValidator('NotEmpty');
        $el->setAttrib('required','');
        if($id > 0) $el->setAttrib('readonly', 'true');
        $el->setAttrib('class', 'form-control');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('ACE_HOR');
        $el->setLabel('Hora')->setRequired(true)
        ->addFilters(array('StripTags','StringTrim'))
        ->addValidator('NotEmpty');
        $el->setAttrib('required','');
        if($id > 0) $el->setAttrib('readonly', 'true');
        $el->setAttrib('class', 'form-control');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('USU_NOM');
        $el->setLabel('Usuário')->setRequired(true)
        ->addFilters(array('StripTags','StringTrim'))
        ->addValidator('NotEmpty');
        $el->setAttrib('required','');
        if($id > 0) $el->setAttrib('readonly', 'true');
        $el->setAttrib('class', 'form-control');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('ACE_IP');
        $el->setLabel('IP')->setRequired(true)
        ->addFilters(array('StripTags','StringTrim'))
        ->addValidator('NotEmpty');
        $el->setAttrib('required','');
        if($id > 0) $el->setAttrib('readonly', 'true');
        $el->setAttrib('class', 'form-control');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('ACE_URL');
        $el->setLabel('URL')->setRequired(true)
        ->addFilters(array('StripTags','StringTrim'))
        ->addValidator('NotEmpty');
        $el->setAttrib('required','');
        if($id > 0) $el->setAttrib('readonly', 'true');
        $el->setAttrib('class', 'form-control');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('ACE_CTL');
        $el->setLabel('Módulo')->setRequired(true)
        ->addFilters(array('StripTags','StringTrim'))
        ->addValidator('NotEmpty');
        $el->setAttrib('required','');
        if($id > 0) $el->setAttrib('readonly', 'true');
        $el->setAttrib('class', 'form-control');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('ACE_ACT');
        $el->setLabel('Ação')->setRequired(true)
        ->addFilters(array('StripTags','StringTrim'))
        ->addValidator('NotEmpty');
        $el->setAttrib('required','');
        if($id > 0) $el->setAttrib('readonly', 'true');
        $el->setAttrib('class', 'form-control');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('ACE_COD');
        $el->setLabel('Código')->setRequired(true)
        ->addFilters(array('StripTags','StringTrim'))
        ->addValidator('NotEmpty');
        $el->setAttrib('required','');
        if($id > 0) $el->setAttrib('readonly', 'true');
        $el->setAttrib('class', 'form-control');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('ACE_COD');
        $el->setLabel('Código ID')->setRequired(true)
        ->addFilters(array('StripTags','StringTrim'))
        ->addValidator('NotEmpty');
        $el->setAttrib('required','');
        if($id > 0) $el->setAttrib('readonly', 'true');
        $el->setAttrib('class', 'form-control');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Textarea('ACE_PST');
        $el->setLabel('Valores do Formulário')->setRequired(true)
        ->addFilters(array('StripTags','StringTrim'))
        ->addValidator('NotEmpty');
        $el->setAttrib('style','width: 500px; height: 150px;');
        $el->setAttrib('required','');
        if($id > 0) $el->setAttrib('readonly', 'true');
        $el->setAttrib('class', 'form-control');
        $this->addElement($el);
        
        Zend_Loader::loadClass('dominio','library');
        
        $arr = dominio::tpoSistemas();
        
        //asort($arr);
        $el = new Zend_Form_Element_Select('ACE_TPO',array('onchange' => ''));
        $el->setLabel('Tipo de Painel')
        ->addMultiOptions($arr);
        if($id > 0) $el->setAttrib('disable', 'true');
        $el->setAttrib('class', 'form-control');
        $this->addElement($el);
        
        
        $el = new Zend_Form_Element('br',array( 'helper'=>'formNote', 'value'=>'&nbsp;' ));
        $this->addElement($el);
        
        if($id == 0){
            $btn = new Zend_Form_Element_Button('Salvar',array('disableLoadDefaultDecorators' =>true));
            $btn->setDecorators(array(array('Description', array('escape' => false, 'tag' => false))));
            $btn->setDescription('<button type="submit" class="btn btn-lg btn-success"><span class="glyphicon glyphicon-floppy-saved" aria-hidden="true"></span> Salvar</button>');
            $this->addElement($btn);
        }
        
        $btn = new Zend_Form_Element_Button('Cancelar',array('disableLoadDefaultDecorators' =>true));
        $btn->setDecorators(array(array('Description', array('escape' => false, 'tag' => false))));
        $btn->setDescription('<a href="'.$url.'" class="btn btn-lg btn-danger"><span class="glyphicon glyphicon-floppy-remove" aria-hidden="true"></span> Cancelar</a>');
        $this->addElement($btn);
        
    }


}

